package com.hu.bgp.server;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import javax.servlet.ServletContext;

import com.hu.bgp.exceptions.CommonException;

/**
 * Laad een configuratiebestand voor het platform
 * 
 * @author ejvos
 */
public class BgpConfiguration
{
	private String barRootPath;
	private String barExtractRootPath;
	private String barResourceDirName;
	private String barConfigFilename;

	public BgpConfiguration(ServletContext context)
	{
		InputStream is = context.getResourceAsStream("/WEB-INF/bgp.properties");
		if (is != null)
		{
			try
			{
				Properties p = new Properties();
				p.load(is);
				barRootPath = p.getProperty("bar.dir");
				barExtractRootPath = p.getProperty("bar.extract.dir");
				barResourceDirName = p.getProperty("bar.resource.dir.name");
				barConfigFilename = p.getProperty("bar.config.filename");
			}
			catch (IOException e)
			{
				throw new CommonException(e);
			}
			try
			{
				is.close();
			}
			catch (IOException e)
			{
				// ignored
			}
		}
	}

	public String getBarRootPath()
	{
		return barRootPath;
	}

	public String getBarExtractRootPath()
	{
		return barExtractRootPath;
	}

	public String getBarResourceDirName()
	{
		return barResourceDirName;
	}

	public String getBarConfigFilename()
	{
		return barConfigFilename;
	}

	public String getResourcesUrlPrefix()
	{
		// DEBUG
		// HACK
		// TODO
		// FIXME put in configuration
		return "/resources/";
	}

	public String getPlayerClientUrlPrefix()
	{
		// DEBUG
		// HACK
		// TODO
		// FIXME put in configuration
		return "/bgp/";
	}
}
